<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  .box {
    width: 600px;
    height: 350px;
    margin: 100px auto;
    border: 1px solid gray;
  }

  .tab-nav {
    width: 600px;
    height: 30px;
  }

  .tab-nav .li {
    float: left;
    list-style: none;
    margin-left: 40px;
    cursor: pointer;
  }

  .active {
    border-bottom: 2px solid red;
    color: pink;
  }

  .content {
    position: relative;
    width: 600px;
    height: 290px;
  }

  .content img {
    width: 600px;
    height: 290px;
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    object-fit: cover;
  }

  .content .active {
    display: block;
  }

  h2 {
    text-indent: 17em;
    font-size: 40px;
    color: rgba(255, 209, 29);
  }
</style>

<body>
  <h2>管睿松</h2>
  <div class="box">
    <ul class="tab-nav">
      <li class="active li">H3C</li>
      <li class="li">小米</li>
      <li class="li">PHP</li>
      <li class="li">华为</li>
    </ul>
    <div class="content">
      <img src="../练习/img/图片1.jpg" alt="" class="active item">
      <img src="../练习/img/图片2.jpg" alt="" class="item">
      <img src="../练习/img/图片3.jpg" alt="" class="item">
      <img src="../练习/img/图片4.jpg" alt="" class="item">
    </div>
  </div>
  <script>
    const nav = document.querySelector('.tab-nav')
    const li = document.querySelectorAll('.tab-nav li')
    for (let i = 0; i < li.length; i++) {
      li[i].addEventListener('mouseenter', function () {
        document.querySelector('.tab-nav .active').classList.remove('active')
        this.classList.add('active')
        document.querySelector('.content .active').classList.remove('active')
        document.querySelector(`.content .item:nth-child(${i + 1})`).classList.add('active')
      })
    }

  </script>
</body>

</html>